package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.shop.common.result.Result;
import com.shop.common.result.util.ResultModel;
import com.shop.entity.MenuConfigDo;
import com.shop.mapper.MenuConfigDoMapper;
import com.shop.service.MenuConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.shopEnum.YesOrNoEnum;
import com.shop.vo.SelectMenuConfigByTypeVo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 菜单配置表 服务实现类
 * </p>
 *
 * @author 靳 旺
 * @since 2021-03-14
 */
@Service
public class MenuConfigServiceImpl extends ServiceImpl<MenuConfigDoMapper, MenuConfigDo> implements MenuConfigService {

    @Override
    public ResultModel selectMenuConfigByType(SelectMenuConfigByTypeVo selectMenuConfigByTypeVo) throws Exception {
        QueryWrapper<MenuConfigDo> queryWrapper = new QueryWrapper<>();
        if (null != selectMenuConfigByTypeVo.getType())
            queryWrapper.eq("config_type", selectMenuConfigByTypeVo.getType());
        queryWrapper.eq("is_del", YesOrNoEnum.NO.code);
        List<MenuConfigDo> menuConfigDos = baseMapper.selectList(queryWrapper);
        menuConfigDos.sort(((o1, o2) -> o1.getConfigSort().compareTo(o2.getConfigSort())));
        Map<Long, List<MenuConfigDo>> longListMap = menuConfigDos.stream().collect(Collectors.groupingBy(MenuConfigDo::getConfigType));
        return Result.successResultModel(longListMap);
    }
}
